﻿@{
    Layout = null;
}

<!DOCTYPE html>

<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
    <meta name="renderer" content="webkit|ie-comp|ie-stand">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta http-equiv="Cache-Control" content="no-siteapp" />
    <meta name="keywords" content="后台管理系统">
    <meta name="description" content="后台管理系统模板">
    <title>登录后台管理系统</title>
    <link href="~/plugins/layui/css/layui.css" rel="stylesheet" />
    <link href="~/plugins/css/sccl.css" rel="stylesheet" />
</head>
<body class="login-bg">
    <div class="login-box">
        <header>
            <h1>框架后台管理系统</h1>
        </header>
        <div class="login-main">
            @using (Html.BeginForm("Login", "LogReg", FormMethod.Post, new { @class = "layui-form" }))
            {
                
                <input name="__RequestVerificationToken" type="hidden" value="">
                <div class="layui-form-item">
                    <label class="login-icon">
                        <i class="layui-icon"></i>
                    </label>
                    <input type="text" name="UserName" lay-verify="userName" autocomplete="off" placeholder="这里输入登录名" class="layui-input">
                </div>
                <div class="layui-form-item">
                    <label class="login-icon">
                        <i class="layui-icon"></i>
                    </label>
                    <input type="password" name="Password" lay-verify="password" autocomplete="off" placeholder="这里输入密码" class="layui-input">
                </div>
                <div class="layui-form-item">
                    <div class="pull-left login-remember">
                        <label>记住帐号？</label>
                        @{
                var check = ViewBag.UserName != null ? "checked" : "";
                        }
                        <input type="checkbox" name="rememberMe" value="true" lay-skin="switch" @check title="记住帐号">
                    </div>
                    <div class="pull-right">
                        <button class="layui-btn layui-btn-primary" lay-submit="" lay-filter="login">
                            <i class="layui-icon"></i> 登录
                        </button>
                    </div>
                    <div class="clear"></div>
                </div>
            }
        </div>
        <footer>
            <p>hzx © 642956057@qq.com</p>
        </footer>
    </div>
    <script type="text/html" id="code-temp">
        <div class="login-code-box">
            <input type="text" class="layui-input" id="code" />
            <img id="valiCode" title="点击刷新" src="@Url.Action("VerificationCode")" />
        </div>
    </script>
    <script src="~/plugins/layui/layui.js"></script>
    <script>
        var errorCount = 0;
        var layer, $, form;
        layui.use(['layer', 'form'], function () {
            layer = layui.layer,
				$ = layui.jquery,
				form = layui.form();

            form.verify({
                userName: function (value) {
                    if (value === '')
                        return '请输入用户名';
                },
                password: function (value) {
                    if (value === '')
                        return '请输入密码';
                }
            });
            form.on('submit(login)', function (data) {
                //window.location.href = "..common/page/index.html";
                if (errorCount > 2) {
                    layer.open({
                        title: '<img src="' + location.origin + '/Plugins/layui/images/face/11.gif" alt="[爱你]"> 输入验证码',
                        type: 1,
                        content: document.getElementById('code-temp').innerHTML,
                        btn: ['确定'],
                        yes: function (index, layero) {
                            var $code = $('#code');
                            if ($code.val() === '') {
                                layer.msg('输入验证码啦，让我知道你是人类 <img src="' + location.origin + '/Plugins/layui/images/face/2.gif" alt="[哈哈]">');
                                isCheck = false;
                            } else {
                                $('input[name=verifyCode]').val();
                                var params = data.field;
                                params.verifyCode = $code.val();
                                submit($, params);
                                layer.close(index);
                            }
                        },
                        area: ['250px', '150px']
                    });
                    $('#valiCode').off('click').on('click', function () {
                        this.src = 'VerificationCode?' + new Date();
                    });
                    VCode();
                } else {
                    submit($, data.field);
                }

                return false;
            });
            //获取验证码
            function VCode() {
                $("#valiCode").attr("src", "@Url.Action("VerificationCode")?" + new Date());
            }
        });
        function submit($, params) {
            $.post('@Url.Action("Login", "LogReg")', params, function (res) {
                if (!res.success) {
                    if (res.data !== undefined)
                        errorCount = res.data.errorCount
                    layer.msg(res.message, { icon: 2 });
                } else {
                    layer.msg(res.message, { icon: 1 }, function (index) {
                        layer.close(index);
                        location.href = '@Url.Action("List","Article")';
                    });
                }
            }, 'json');
        }
        //function submit($, params) {
        //    $.post('Login', params, function (res) {
        //        if (!res.success) {
        //            errorCount = res.errorCount;
        //            layer.msg(res.message, { icon: 2 });
        //        } else {
        //            errorCount = res.errorCount;
        //            layer.msg(res.message, { icon: 1,time:1000 }, function (index) {
        //                layer.close(index);
        //                location.href = res.sUrl;
        //            });
        //        }
        //    }, 'json');
        //}
    </script>
</body>
</html>
